home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / examples / slave1.f < prev    next >
Text File  |  1997-07-22  |  2KB  |  79 lines

  1. c
  2. c $Id: slave1.f,v 1.1 1996/09/23 20:55:35 pvmsrc Exp $
  3. c
  4.       program slave1 
  5.       include '../include/fpvm3.h'
  6. c ------------------------------------------------------
  7. c Example fortran program illustrating use of PVM 3
  8. c ------------------------------------------------------
  9.       integer  info, mytid, mtid, msgtype, me
  10.       integer  tids(0:32)
  11.       double precision result, data(100)
  12.       double precision work
  13.  
  14. c  Enroll this program in PVM 
  15.       call pvmfmytid( mytid )
  16. c  Get the master's task id
  17.       call pvmfparent( mtid )
  18.  
  19. c ------- Begin user program -------- 
  20.  
  21. c     Receive data from host 
  22.       msgtype  = 1 
  23.       call pvmfrecv( mtid, msgtype, info ) 
  24.       call pvmfunpack( INTEGER4, nproc, 1, 1, info )
  25.       call pvmfunpack( INTEGER4, tids, nproc, 1, info )
  26.       call pvmfunpack( INTEGER4, n, 1, 1, info )
  27.       call pvmfunpack( REAL8,    data, n, 1, info ) 
  28.  
  29. c     Determine which slave I am (0 -- nproc-1)
  30.       do 5 i=0, nproc
  31.          if( tids(i) .eq. mytid ) me = i
  32.   5   continue
  33.       
  34. c     Do calculations with data
  35.       result = work( me, n, data, tids, nproc ) 
  36.                     
  37. c     Send result to host 
  38.       call pvmfinitsend( PVMDEFAULT, info )
  39.       call pvmfpack( INTEGER4, me, 1, 1, info )
  40.       call pvmfpack( REAL8,    result, 1, 1, info )
  41.       msgtype  = 2 
  42.       call pvmfsend( mtid, msgtype, info ) 
  43.  
  44. c --------- End user program -------- 
  45.  
  46. c     Program finished. Leave PVM before exiting 
  47.       call pvmfexit(info) 
  48.       stop
  49.       end
  50.  
  51.       double precision function work( me, n, data, tids, nproc )
  52.       include '../include/fpvm3.h'
  53. c    --------------------------------------
  54. c     Just a simple routine for illustration
  55. c    --------------------------------------
  56.       double precision data(*), sum, psum
  57.       integer i, n, me, inum
  58.       integer tids(0:*)
  59.  
  60.       sum = 0.0
  61.       do 10 i=1,n
  62.          sum = sum + me * data(i)
  63.  10   continue
  64. c     ----------------------------------------
  65. c     Pass partial result to neighboring node
  66. c     to illustrate node-to-node communication
  67. c     ----------------------------------------
  68.       call pvmfinitsend( PVMDEFAULT, info )
  69.       call pvmfpack( REAL8, sum, 1, 1, info)
  70.       inum = me+1
  71.       if( inum .eq. nproc ) inum = 0
  72.       call pvmfsend( tids(inum), 77, info )
  73.       call pvmfrecv(  -1, 77, info )
  74.       call pvmfunpack( REAL8, psum, 1, 1, info)
  75.  
  76.       work = sum + psum
  77.       return
  78.       end
  79.